package com.jiang.sevice.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jiang.dao.IMemberDAO;
import com.jiang.sevice.IMemberService;
import com.jiang.vo.Member;

/**
 * @author Administrator
 *
 */
@Service
public class MemberServiceImpl implements IMemberService {

	// 由spring产生dao实现类, 系统产生的dao会自己运行完备后关闭
	@Autowired
	private IMemberDAO memberDAO;
	
	@Override
	public Member getById(String mid) {
		
		Member member = null;
		try {
			member = memberDAO.findById(mid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return member;
	}

	/* (non-Javadoc)
	 * @see com.jiang.sevice.IMemberService#listAuthByMember(java.lang.String)
	 */
	@Override
	public Map<String, Object> listAuthByMember(String mid) {
		
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			Set<String> roles_id = memberDAO.listRolesByMid(mid);
			Set<String> permisson_id = memberDAO.listPermissionsByMid(mid);
			map.put("roles", roles_id);
			map.put("permissions", permisson_id);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return map;
	}

}
